package com.itheima;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
*  2025/5/21 16:43
* 
*/
public class StreamDemo {
    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("赵六");
        list.add("张三丰");
        list.add("张三丰");
        list.add("张三丰");
        list.add("张三丰");
        list.add("张无忌");
        list.add("赵敏");
        list.add("张三李四");

//        List<String> list1 = new ArrayList<>();
//        list.forEach(name -> {
//            if (name.startsWith("张")&&name.length()==3){
//                list1.add(name);
//            }
//
//        });
//        list1.forEach(System.out::println);

        list.stream()
                .map(String::toUpperCase)
                .skip(1)
                .filter(name -> name.startsWith("张"))
                .filter(name -> name.length() == 3)
                .distinct()
                .limit(1)
                .forEach(System.out::println);

        List<Integer> integerList = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        List<Integer> collect = integerList.stream().filter(num -> num % 2 == 0)
                .collect(Collectors.toList());
        System.out.println(collect);

        List<String> list2 = new ArrayList<>();

        list2.add("zhangsan,23");
        list2.add("lisi,24");
        list2.add("wangwu,25");
        list2.add("zhaoliu,26");

        Map<Object, Object> map = list2.stream().filter(name -> {
            String[] split = name.split(",");
            return Integer.parseInt(split[1]) > 24;
        }).collect(Collectors.toMap((Function<String, Object>) s -> s.split(",")[0], (Function<String, Object>) s -> s.split(",")[1]));

        map.forEach((k,v)->{
            System.out.println(k+"--"+v);
        });

        List<Actor> list3 = new ArrayList<>();
        List<Actor> list4 = new ArrayList<>();

        list3.add(new Actor("张三丰", "男"));
        list3.add(new Actor("张三", "男"));
        list3.add(new Actor("李四", "男"));
        list3.add(new Actor("王五", "男"));
        list3.add(new Actor("赵六", "男"));
        list3.add(new Actor("张无忌", "男"));

        list4.add(new Actor("孙俪", "女"));
        list4.add(new Actor("林志玲", "女"));
        list4.add(new Actor("关晓彤", "女"));
        list4.add(new Actor("赵丽颖", "女"));
        list4.add(new Actor("赵薇", "女"));
        list4.add(new Actor("赵敏", "女"));

        Stream.concat(list3.stream().filter(actor -> actor.getName().length()==3).limit(2),list4.stream().skip(1).filter(actor -> actor.getName().startsWith("赵"))).forEach(System.out::println);

    }
}
